<template>
  <div>
    <UserSelect ref="userSelect" @e-userData="setUserId" />
  </div>
</template>
<script>
import { eduTeachingStudentAddBatch } from '@/api/admin/teach/eduTeachingStudent.js'
import Bus from '@/utils/bus.js'
export default {
  components: {
    UserSelect: () => import('@/components/userSelect'),
  },
  data() {
    return {
      form: {
        eduTeachingId: undefined,
        studentId: undefined,
        studentName: undefined,
      },
      row: undefined,
    }
  },
  mounted() {
    Bus.$on('showAddStudent', (row) => {
      this.row = row
      Bus.$emit('userSelect')
    })
  },
  beforeDestroy() {
    Bus.$off('showAddStudent')
  },
  methods: {
    setUserId(obj) {
      let arr = obj.userId
      let list = []
      if (arr.length > 0) {
        arr.forEach((item) => {
          list.push({
            eduTeachingId: this.row.id,
            studentId: item.id,
            studentName: item.userName,
          })
        })
        this.add(list)
      }
    },
    async add(list) {
      // console.log(list)
      // return
      await eduTeachingStudentAddBatch(list)
      this.$message({
        message: '操作成功',
        type: 'success',
      })
    },
  },
}
</script>
<style scoped lang="scss">
</style>